<template>
	<view class="content">
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<uni-nav-bar left-icon="back" left-text="返回" title="患者列表"></uni-nav-bar>
		<view class="body">
			<view class="content-choose">
				<view class="content-choose-item" @click="dianji(1)" :class="{ active: show == 1 }" :current="current">基本信息</view>
				<view class="content-choose-item" @click="dianji(2)" :class="{ active: show == 2 }" :current="current">服药记录</view>
				<view class="content-choose-item" @click="dianji(3)" :class="{ active: show == 3 }" :current="current">走访记录</view>
				<view class="content-choose-item" @click="dianji(4)" :class="{ active: show == 4 }" :current="current">异常情况</view>
			</view>
			<view class="base_info" v-if="current === 1">
				<view class="name info">
					<view class="title">
						姓名
					</view>
					{{name}}
				</view>
				<view class="sex info">
					<view class="title">
						性別
					</view>
					{{sex}}
				</view>
				<view class="patient_num info">
					<view class="title">
						患者编号
					</view>
					{{sid}}
				</view>
				<view class="address info">
					<view class="title">
						地址
					</view>
					{{address}}
				</view>
				<view class="guardian info">
					<view class="title">
						监护人
					</view>
					{{guardianName}}
				</view>
				<view class="guardian_tel info">
					<view class="title">
						监护人电话
					</view>
					{{guardianPhone}}
				</view>
				<view class="QR_code">
					<image src="../../static/patient_list/QR-code.png"></image>
				</view>
				<view class="tips" @click="handleShow(5)">
					扫描此二维码用于患者家属认领患者
				</view>
			</view>
			<view class="record" v-if="current ==2">
				<scroll-view scroll-y="true" class="scroll_list" @scrolltolower="loadMore">
					<view class="scroll_item" v-for="(item , index) in list" :key="index">
						<view class="imgList" v-for="imgs in item.imgList" :key="imgs.sid" v-if="item.imgList.length != 0">
							<image :src="imgs.url" class="recordImgs"></image>
						</view>
						<view class="imgList"  v-if="item.imgList.length == 0">
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
						</view>
						<view class="info_detail">
							<view class="top">
								<view class="status" v-if="item.state == 0">已服药</view>
								<view class="status" v-if="item.state == 1">未服药</view>
								<view class="status" v-if="item.state == 2">异常</view>
								<view class="time">
									{{item.createTime | subTime}}
								</view>
							</view>
							<view class="bottom" v-if="item.place == null">
								暂无地址
							</view>
							<view class="bottom" v-if="item.place != null">
								{{item.place}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="record" v-if="current ==3">
				<!-- #ifdef H5 -->
				<scroll-view scroll-y class="scroll_list" @scrolltolower="loadMore">
					<view class="scroll_item">
						<view class="info_detail">
							<view class="top">
								<view class="status">未拜访</view>
								<view class="time">
									item.
								</view>
							</view>
							<view class="bottom">
								暂无地址
							</view>
						</view>
					</view>
				</scroll-view>
				<!-- #endif -->
				<scroll-view scroll-y="true" class="scroll_list" @scrolltolower="loadMore">
					<view class="scroll_item" v-for="(item , index) in list" :key="index">
						<view class="imgList" v-for="imgs in item.imgList" :key="imgs.sid" v-if="item.imgList.length != 0">
							<image :src="imgs.url" class="recordImgs"></image>
						</view>
						<view class="imgList"  v-if="item.imgList.length == 0">
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
						</view>
						<view class="info_detail">
							<view class="top">
								<view class="status" v-if="item.state == 0">未拜访</view>
								<view class="status" v-if="item.state == 1">已拜访</view>
								<view class="status" v-if="item.state == 2">超期未拜访</view>
								<view class="time">
									{{item.createTime | subTime}}
								</view>
							</view>
							<view class="bottom" v-if="item.place == null">
								暂无地址
							</view>
							<view class="bottom" v-if="item.place != null">
								{{item.place}}
							</view>
						</view>
					</view>
					<uni-load-more :status="status"></uni-load-more>
				</scroll-view>

			</view>
			<view class="record" v-if="current ==4">
				<scroll-view scroll-y="true" class="scroll_list" @scrolltolower="loadMore">
					<view class="scroll_item" v-for="(item , index) in list" :key="index">
						<view class="imgList" v-for="imgs in item.imgList" :key="imgs.sid" v-if="item.imgList.length != 0">
							<image :src="imgs.url" class="recordImgs"></image>
						</view>
						<view class="imgList"  v-if="item.imgList.length == 0">
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
							<image src="../../static/null.png" class="recordImgs"></image>
						</view>
						<view class="info_detail">
							<view class="top">
								<view class="status" v-if="item.state == 0">未操作</view>
								<view class="status" v-if="item.state == 1">已操作</view>
								<view class="status" v-if="item.state == 2">超期</view>
								<view class="time">
									{{item.createTime | subTime}}
								</view>
							</view>
							<view class="bottom" v-if="item.place == null">
								暂无地址
							</view>
							<view class="bottom" v-if="item.place != null">
								{{item.place}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<xy-dialog title="已认领成功!" :show="showDialog_5" :isShowCancel="!showDialog_5" @confirmButton="clickConfirm(5)"></xy-dialog>
	</view>
</template>

<script>
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	import xyDialog from '@/components/xy-dialog/xy-dialog.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore,
			uniNavBar,
			xyDialog
		},
		data() {
			return {
				showDialog_5: false,
				current: 1,
				show: 1,
				name: '',
				sex: '',
				sid: '',
				address: '',
				guardianName: '',
				guardianPhone: '',
				page: 1,
				limit: 12,
				list: [],
				status: 'more',
				totalCount: 0
			}
		},
		filters: {
			subTime: function(value) {
				return value.substr(0, 10);
			}
		},
		onLoad: function(options) {
			console.log("options: " + JSON.stringify(options));
			var data = JSON.parse(options.info);
			this.name = data.name;
			this.sex = data.sex;
			this.sid = data.sid;
			this.address = data.address;
			this.guardianName = data.guardianName;
			this.guardianPhone = data.guardianPhone;
		},
		methods: {
			getList() {
				this.page = 1;
				var json = new Object();
				json.page = this.page;
				json.limit = this.limit;
				json.patientSid = this.sid;
				this.$http.uniHttpPost(this.$api.server_patient_visit_list, json).then(res => {
					console.log("res: " + JSON.stringify(res));
					var data = res.data;
					this.totalCount = data.count;
					console.log("totalcount:" + this.totalCount);
					if (this.page * this.limit >= data.count) {
						this.status = 'noMore';
					}
					console.log("data: " + JSON.stringify(data));
					this.list = data.data;
					uni.hideLoading();
					console
				}).catch(err => {
					uni.hideLoading();
					console.log("err: " + JSON.stringify(err));
				})
			},
			getDurgList() {
				this.page = 1;
				var json = new Object();
				json.page = this.page;
				json.limit = this.limit;
				json.patientSid = this.sid;
				this.$http.uniHttpPost(this.$api.server_patient_drug_list, json).then(res => {
					console.log("res: " + JSON.stringify(res));
					var data = res.data;
					this.totalCount = data.count;
					console.log("totalcount:" + this.totalCount);
					if (this.page * this.limit >= data.count) {
						this.status = 'noMore';
					}
					console.log("data: " + JSON.stringify(data));
					this.list = data.data;
					uni.hideLoading();
					console
				}).catch(err => {
					uni.hideLoading();
					console.log("err: " + JSON.stringify(err));
				})
			},
			getErrList() {
				this.page = 1;
				var json = new Object();
				json.page = this.page;
				json.limit = this.limit;
				json.patientSid = this.sid;
				this.$http.uniHttpPost(this.$api.server_abnormal_list, json).then(res => {
					console.log("res: " + JSON.stringify(res));
					var data = res.data;
					this.totalCount = data.count;
					console.log("totalcount:" + this.totalCount);
					if (this.page * this.limit >= data.count) {
						this.status = 'noMore';
					}
					console.log("data: " + JSON.stringify(data));
					this.list = data.data;
					uni.hideLoading();
					console
				}).catch(err => {
					uni.hideLoading();
					console.log("err: " + JSON.stringify(err));
				})
			},
			loadMore() {
				console.log("加载更多。。。");
				this.status = 'loading';
				this.page += 1;
				var json = new Object();
				json.page = this.page;
				json.limit = this.limit;
				json.patientSid = this.sid;
				setTimeout(() => {
					this.$http.uniHttpPost(this.$api.server_patient_visit_list, json).then(res => {
							this.list = this.list.concat(res.data.data);
							this.status = 'more';
							this.totalCount = res.data.count;
							if (this.page * this.limit >= this.totalCount) {
								this.status = 'noMore';
							}
						})
						.catch(err => {
							console.log('request fail', err);
						});
				}, 1200);
			},
			dianji(index) {
				console.log(index);
				if (this.current !== index && this.show !== index) {
					this.current = index;
					this.show = index;
				}
				if(index == 2){
						uni.showLoading({
						title: "获取数据中..."
					})
					this.getDurgList();
				}
				if (index == 3) {
					uni.showLoading({
						title: "获取数据中..."
					})
					this.getList();
				}
					if (index == 4) {
					uni.showLoading({
						title: "获取数据中..."
					})
					this.getErrList();
				}
			},
			handleShow(type) {
				this[`showDialog_${type}`] = true;
				console.log(123);
			},
			clickCancel(type) {
				this[`showDialog_${type}`] = false;
			},
			clickConfirm(type) {
				this[`showDialog_${type}`] = false;
			},
			handleActionShow() {
				this.$refs.xyDialog.show()
			}
		}
	}
</script>

<style scoped>
	@import url('../../css/navigation.css');

	.content {
		background-color: #F2F2F2;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.body {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.title {
		font-size: 25upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgb(41, 209, 203);
		flex: 1;
		margin-left: 20.83upx;
	}

	.info {
		font-size: 25upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgb(0, 0, 0);
		display: flex;
		flex-direction: row;
		padding-right: 20.83upx;
		height: 78.47upx;
		align-items: center;
		border-bottom: 0.69upx solid rgba(0, 0, 0, 0.302);
		background-color: #FFFFFF;
	}

	.QR_code {
		display: flex;
		justify-content: center;
	}

	.QR_code image {
		margin-top: 111.11upx;
		width: 315.97upx;
		height: 328.47upx;
	}

	.tips {
		margin-top: 65.97upx;
		font-size: 29.16upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgb(41, 209, 203);
		text-align: center;
	}

	.content-choose {
		width: 100%;
		display: flex;
		flex-direction: row;
		background-color: #29d1cb;
	}

	.content-choose-item {
		flex: 1;
		height: 55.55upx;
		text-align: center;
		line-height: 55.55upx;
		font-size: 30upx;
		font-family: 'PingFang SC';
		color: #ffffff;
	}

	.active {
		border-bottom: 3px solid rgb(255, 255, 255);
	}

	.base_info {
		margin-top: 5.55upx;
	}

	.record {
		margin-top: 13.88upx;
		display: flex;
		justify-content: center;
		flex: 1;
		flex-direction: column;
	}

	.content_item {
		display: flex;
		flex-direction: row;
		padding: 20.83upx 0;
		align-items: center;
		border-bottom: 1px solid rgba(0, 0, 0, 0.3);
	}

	.scroll_item {
		display: flex;
		flex-direction: row;
		padding: 13.88upx 17.36upx;
		background-color: #FFFFFF;
		margin-bottom: 17.36upx;
		justify-content: flex-end;
	}

	.imgList {
		flex: 1;
		display: flex;
		align-items: center;
	}

	.recordImgs {
		width: 100upx;
		height: 67.36upx;
		margin-right: 6.94upx;
	}

	.info_detail {
		display: flex;
		flex-direction: column;
	}

	.info_detail .top {
		display: flex;
		flex-direction: row;
	}

	.info_detail .top .status {
		border-width: 0.69upx;
		border-color: rgb(228, 228, 228);
		border-style: solid;
		background-color: rgb(247, 142, 5);
		padding: 6.94upx 13.88upx;
		height: 36.8upx;
		border-radius: 19.09upx;
		font-size: 25upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgb(255, 255, 255);
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 10.41upx;
	}

	.info_detail .top .time {
		font-size: 34.02upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgb(41, 209, 203);
	}

	.info_detail .bottom {
		font-size: 25upx;
		font-family: "FZLanTingHeiS-R-GB";
		color: rgba(0, 0, 0, 0.6);
		display: flex;
	}

	.scroll_list {
		flex: 1;
		display: flex;
		flex-direction: column;
	}
</style>
